<template>
  <div id="index">
    <!-- 顶部导航栏 -->
    <el-container>
      <el-header style="background-color: #02366d; padding: 0">
        <div class="header-content">
          <div class="header-left">
            <el-menu
              :default-active="activeMenuIndex"
              class="el-menu-demo"
              mode="horizontal"
              background-color="#02366d"
              text-color="#fff"
              active-text-color="#ffd04b"
              router
            >
              <el-menu-item index="/index/home">
                <i class="el-icon-s-home"></i>
                <span slot="title">首页</span>
              </el-menu-item>
              <el-menu-item index="/index/dispatch">
                <i class="el-icon-s-promotion"></i>
                <span slot="title">调度</span>
              </el-menu-item>
              <el-menu-item index="/index/monitor">
                <i class="el-icon-monitor"></i>
                <span slot="title">监控</span>
              </el-menu-item>
            </el-menu>
          </div>
          <div class="header-center">
            <h1 style="color: #fff; margin: 0; font-size: 24px">
              乡村特色产业社会化服务资源
            </h1>
          </div>
          <div class="header-right">
            <el-menu
              :default-active="$route.path"
              class="el-menu-demo"
              mode="horizontal"
              background-color="#02366d"
              text-color="#fff"
              active-text-color="#ffd04b"
              router
            >
              <el-menu-item index="/index/management">
                <i class="el-icon-s-tools"></i>
                <span slot="title">管理</span>
              </el-menu-item>
              <el-menu-item index="/index/analyze">
                <i class="el-icon-data-analysis"></i>
                <span slot="title">分析</span>
              </el-menu-item>
              <div class="header-info">
                <div class="current-date">{{ currentDate }}</div>
                <el-dropdown>
                  <span class="user-info">
                    <i class="el-icon-user"></i>
                    <span>管理员</span>
                    <i class="el-icon-arrow-down el-icon--right"></i>
                  </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>个人中心</el-dropdown-item>
                    <el-dropdown-item>系统设置</el-dropdown-item>
                    <el-dropdown-item divided @click.native="logout"
                      >退出登录</el-dropdown-item
                    >
                  </el-dropdown-menu>
                </el-dropdown>
              </div>
            </el-menu>
          </div>
        </div>
      </el-header>

      <el-main
        style="
          padding: 10px;
          background-color: #0c1e3e;
          height: calc(100vh - 80px);
          overflow-y: auto;
        "
      >
        <!-- 路由视图 -->
        <router-view />
      </el-main>
    </el-container>
  </div>
</template>

<script>
import moment from "moment";

export default {
  name: "Index",
  data() {
    return {
      currentDate: "",
    };
  },
  computed: {
    activeMenuIndex() {
      return this.$route.path;
    },
  },
  mounted() {
    this.setCurrentDate();
  },
  methods: {
    setCurrentDate() {
      this.currentDate = moment().format("YYYY年MM月DD日");
    },
    logout() {
      this.$confirm("确定要退出登录吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          // 在实际应用中，这里应该调用退出登录的API
          // 然后清除本地存储的token等信息
          localStorage.removeItem("token");
          this.$message.success("退出成功");
          this.$router.push("/login");
        })
        .catch(() => {
          // 用户取消操作
          this.$message.error("已取消");
        });
    },
  },
};
</script>

<style scoped>
/* 整体布局样式 */
#index {
  font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB",
    Arial, sans-serif;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 60px;
  padding: 0 30px;
}

.header-left,
.header-right {
  min-width: 280px;
}

.header-center {
  flex: 1;
  text-align: center;
}

.header-center h1 {
  color: #fff;
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 2px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* 菜单样式优化 */
.el-menu--horizontal {
  border-bottom: none;
  display: flex;
  align-items: center;
}

.el-menu--horizontal .el-menu-item {
  height: 56px;
  line-height: 54px;
  border-bottom: 2px solid transparent;
  margin: 0 5px;
  font-size: 14px;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.el-menu--horizontal .el-menu-item:hover {
  background-color: rgba(255, 208, 75, 0.1) !important;
  transform: translateY(-1px);
}

.el-menu--horizontal .el-menu-item.is-active {
  border-bottom-color: #ffd04b;
  background-color: rgba(255, 208, 75, 0.15) !important;
}

.el-menu--horizontal .el-menu-item i {
  margin-right: 6px;
  font-size: 16px;
}

/* 右侧用户信息区域 */
.header-info {
  display: flex;
  align-items: center;
  margin-left: 25px;
  gap: 12px;
}

.current-date {
  color: #a8c7fa;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.user-info {
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  border-radius: 4px;
  transition: background-color 0.3s ease;
  font-weight: 500;
}

.user-info:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.user-info i:first-child {
  font-size: 16px;
  color: #ffd04b;
}

/* 下拉菜单样式 */
.el-dropdown-menu {
  background: linear-gradient(135deg, #02366d 0%, #03478f 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.el-dropdown-menu__item {
  color: #fff;
  font-size: 13px;
  transition: all 0.3s ease;
}

.el-dropdown-menu__item:hover {
  background-color: rgba(255, 208, 75, 0.2);
  color: #ffd04b;
}

.el-dropdown-menu__item--divided {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* 主内容区域 */
.el-main {
  padding: 15px;
  background: linear-gradient(135deg, #0c1e3e 0%, #152a4e 50%, #0c1e3e 100%);
  height: calc(100vh - 60px);
  overflow-y: auto;
  position: relative;
}

/* 滚动条美化 */
.el-main::-webkit-scrollbar {
  width: 6px;
}

.el-main::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
}

.el-main::-webkit-scrollbar-thumb {
  background: rgba(255, 208, 75, 0.5);
  border-radius: 3px;
}

.el-main::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 208, 75, 0.7);
}

/* 响应式设计 */
@media screen and (max-width: 1200px) {
  .header-content {
    padding: 0 20px;
  }

  .header-left,
  .header-right {
    min-width: 240px;
  }

  .header-center h1 {
    font-size: 19px;
    letter-spacing: 1px;
  }
}

@media screen and (max-width: 768px) {
  .header-content {
    flex-direction: column;
    height: auto;
    padding: 15px 20px;
  }

  .header-left,
  .header-right,
  .header-center {
    width: 100%;
    min-width: auto;
  }

  .header-center {
    order: -1;
    margin-bottom: 10px;
  }

  .header-center h1 {
    font-size: 18px;
  }

  .header-info {
    justify-content: center;
    margin-left: 0;
    margin-top: 10px;
  }
}
</style>
